package com.jiufen.Service.impl;

import com.jiufen.Mapper.EmpMapper;
import com.jiufen.Mapper.StudentMapper;
import com.jiufen.Pojo.JobOption;
import com.jiufen.Pojo.StudentCountOption;
import com.jiufen.Service.ReportService;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Slf4j
@Service
public class ReportServiceImpl implements ReportService {

    @Autowired
    private EmpMapper empMapper;

    @Autowired
    private StudentMapper studentMapper;

    @Override
    public JobOption getEmpJobDataReport() {
        //1.获取统计数据
        List<Map<String, Object>> list = empMapper.countEmpJobData(); //map : pos 教研主管，num = 1
        log.info("员工职位统计结果：{}", list);
        //2.组装结果，进行返回
        List<Object> jobList =  list.stream().map(dataMap -> dataMap.get("position")).toList();
        List<Object> dataList =  list.stream().map(dataMap -> dataMap.get("num")).toList();

        //兼容java1.8
        /**
        List<Object> jobList = list.stream()
                .map(dataMap -> dataMap.get("position"))
                .collect(Collectors.toList());

        List<Object> dataList = list.stream()
                .map(dataMap -> dataMap.get("num"))
                .collect(Collectors.toList());
        */
        log.debug("职位列表：{}", jobList);
        log.debug("职位数量：{}", dataList);
        return new JobOption(jobList,dataList);
    }

    @Override
    public List<Map<String,Object>> getEmpGenderDataReport() {
        List<Map<String,Object>> genderList =  empMapper.countEmpGenderData();
        return genderList;
    }

    @Override
    public List<Map<String, Object>> getStudentDegreeDataReport() {
        List<Map<String,Object>> studentDegreeList =  empMapper.countStudentDegreeData();
        log.info("学生学历信息统计结果：{}", studentDegreeList);
        return studentDegreeList;

    }

    @Override
    public StudentCountOption getStudentCountDataReport() {
        List<Map<String,Object>> List = studentMapper.StudentCountData();
        log.debug("班级人数信息={}",List);
        //2.组装结果，进行返回
        List<Object> clazzList =  List.stream().map(dataMap -> dataMap.get("clazzName")).toList();
        List<Object> dataList =  List.stream().map(dataMap -> dataMap.get("number")).toList();
        log.debug("班级列表：{}", clazzList);
        log.debug("人数数量：{}", dataList);
        return new StudentCountOption(clazzList,dataList);
    }
}
